<%@ include file="/WEB-INF/jsp/common/include.jsp" %>
<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib prefix="app" uri="AppTags" %>
<script type="text/javascript" src="<app:slaveServerUrl />/js/bac/search.js"></script>
<script type="text/javascript" src="<app:slaveServerUrl />/js/bac/common.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/ui-lightness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script type="text/javascript" src="<app:slaveServerUrl />/js/jquery/plugins/jquery.autocomplete.js"></script>
<script type="text/javascript">
  var minPrice = 100;
  var maxPrice = 500;
  var step = 50;
  var curMinPrice = minPrice - step;
  <c:if test="${not empty searchParameters.minPrice}">
  curMinPrice = <c:out value="${searchParameters.minPrice}"/>;
  </c:if>
  var curMaxPrice = maxPrice + step;
  <c:if test="${not empty searchParameters.maxPrice}">
  curMaxPrice = <c:out value="${searchParameters.maxPrice}"/>;
  </c:if>
  $(function() {
    updatePriceRangeLabel(curMinPrice, curMaxPrice);
    $("#locationLabel").autocomplete("/autocomplete/address.do", {
      width: 260,
      matchCase: 1,
      selectFirst: false,
      extraParams: {city : function(){return $('#city').val()}},
      filterResults : false
    });
  });
  var selectedAdMapTab = false;
  var AdMapTab = false;
  <tiles:getAsString name='adMapTab' ignore='true'/>MapTab = true;
  function updateSearchFormAction(citySelect){
    var city = citySelect.value;
    var urlPrefix = 'http://www' + (city == 'minsk' ? '' : '.' + city) + '.hatu.by';
    if(selectedAdMapTab){
      citySelect.form.action = urlPrefix + '/ad/search/map.do';
    }
    else{
      citySelect.form.action = urlPrefix + '/ad/search/' + city + '/0/list.do';
    }
  }
</script>
<script type="text/javascript" src="<app:slaveServerUrl />/js/jquery/plugins/jquery.hotkeys.min.js"></script>
<div class="lpanel">
  <!--Search-->
  <div id="search" class="white-box box-container box">
        <h2>Поиск</h2>
        <form:form method="get" commandName="searchParameters">
          <p>
            <label>Город:</label>
            <span id="cityChange" class="select">
              <form:select path="city" onchange="updateSearchFormAction(this)">
                <form:option value="minsk"><fmt:message key="label.city.minsk"/></form:option>
                <form:option value="mogilev"><fmt:message key="label.city.mogilev"/></form:option>
              </form:select>
              <b><span class="link"><spring:message code="label.city.${searchParameters.city}" /></span></b>
            </span>
          </p>
          <p>
            <label>Комнатаж:</label>
            <span id="roomChange" class="select">
              <form:select path="room">
                <form:option value="">любой</form:option>
                <form:option value="1">однокомнатная квартира</form:option>
                <form:option value="2">двухкомнатная квартира</form:option>
                <form:option value="3">трёхкомнатная квартира</form:option>
              </form:select>
              <b><span class="link"><spring:message code="label.selectRoom${searchParameters.room}" /></span></b>
            </span>
          </p>
          <p><label>Цена:</label> <span id="price-range-label"></span></p>
          <p id="price-range"></p>
          <form:hidden path="minPrice"/>
          <form:hidden path="maxPrice"/>
          <p>
            <label>Учитывать расстояние до места  работы:</label>
            <form:input path="locationLabel" cssStyle="width:100%" onchange="clearLocation(); return true;"/><img class="processing locationLabel" style="display: none" src="<app:slaveServerUrl />/image/processing.gif"/>
            <form:errors path="locationLabel" cssClass="errorBlock" />
            <a class="psevdo" href="#" onclick="window.open('/easysearch/geoLocation/map.do','locationEasysearch','width=800,height=600')">Выбрать на карте</a>&nbsp;&nbsp;<a class="psevdo" href="#" onclick="clearLocation()">Очистить</a>
            <form:hidden path="lat"/>
            <form:hidden path="lon"/>
          </p>
          <c:if test="${loggedIn}">
            <input type="hidden" name="loggedIn" value="true"/>
          </c:if>
          <p><span class="button"><button type="submit">Найти</button></span></p>
        </form:form>
  </div>
  <!--Search-->
</div>
<div class="main">
  <!--Paging + Tabs-->
  <div class="paging with-tabs white-box">
    <ul>
      <tiles:insertTemplate template="list/prevButton.jsp"/>
      <tiles:insertTemplate template="list/nextButton.jsp"/>
    </ul>
    <p>
      <c:url value="/ad/search/${searchParameters.city}/0/list.do" var="listLink">
        <c:param name="minPrice" value="${searchParameters.minPrice}"/>
        <c:param name="maxPrice" value="${searchParameters.maxPrice}"/>
        <c:param name="room" value="${searchParameters.room}"/>
        <c:param name="city" value="${searchParameters.city}"/>
      </c:url>
      <c:url value="/ad/search/map.do" var="mapLink">
        <c:param name="minPrice" value="${searchParameters.minPrice}"/>
        <c:param name="maxPrice" value="${searchParameters.maxPrice}"/>
        <c:param name="room" value="${searchParameters.room}"/>
        <c:param name="city" value="${searchParameters.city}"/>
      </c:url>
      <span class="tab <tiles:getAsString name='adListTab' ignore='true'/>"><a class="psevdo" href="${listLink}">Список </a><span
          class="s l"></span><span class="s r"></span></span>
      <span class="tab <tiles:getAsString name='adMapTab' ignore='true'/>"><a class="psevdo" href="${mapLink}">Карта </a><span
          class="s l"></span><span class="s r"></span></span>
    </p>
  </div>
  <!--Paging + Tabs-->

  <tiles:insertAttribute name="searchResult" />
  <!--Paging-->
  <div class="box google-ad">
    <div class="white-box" style="padding: 15px">

      <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
      <!-- hatu-by-bottom-responsive -->
      <ins class="adsbygoogle"
           style="display:block"
           data-ad-client="ca-pub-2127591047178376"
           data-ad-slot="2708728641"
           data-ad-format="auto"></ins>
      <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
      </script>

    </div>
  </div>
  <div class="counters">
    <!-- begin of Top100 code -->

    <script id="top100Counter" type="text/javascript" src="http://counter.rambler.ru/top100.jcn?2339557"></script>
    <noscript>
      <a href="http://top100.rambler.ru/navi/2339557/">
        <img src="http://counter.rambler.ru/top100.cnt?2339557" alt="Rambler's Top100" border="0" />
      </a>

    </noscript>
    <!-- end of Top100 code -->
  </div>

  <!--Map-->
  <div id="map" style="display:none;"><p>Карта</p></div>
  <!--Map-->
  <div class="box copy">
    <div class="white-box" style="padding: 20px 20px 10px 20px">
      <p>
        Сайт помог тебе? Скажи спасибо:
      </p>
      <p>
        <g:plusone></g:plusone>
        <script type="text/javascript">
          (function() {
            var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
            po.src = 'https://apis.google.com/js/plusone.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
          })();
        </script>
      </p>
      <p>
        Эл. почта: <a href="mailto:support@hatu.by">support@hatu.by</a>
      </p>
    </div>
  </div>